package com.sld.integrate.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class IotSDKConfig {

    @Value("${alibaba.accessKeyId}")
    String accessKeyId;

    @Value("${alibaba.accessKeySecret}")
    String accessKeySecret;

    @Value("${alibaba.iot.regionId}")
    String regionId;


    @Bean
    public DefaultAcsClient createIotClient() throws Exception{
        IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(profile); //初始化SDK客户端。
        return client;
//        PubRequest request = new PubRequest();
//        request.setIotInstanceId(iotInstanceId);
//        request.setProductKey("gqzoIEU0h1a");
//        request.setMessageContent(Base64.encodeBase64String("18".getBytes()));
//        request.setTopicFullName("/sys/gqzoIEU0h1a/d001/thing/service/TanSun");
//        request.setQos(0); //目前支持QoS0和QoS1。
//        PubResponse response = client.getAcsResponse(request);
//        System.out.println(response.getSuccess());
//        System.out.println(response.getCode());
//        System.out.println(response.getErrorMessage());

    }
}
